﻿package mortal.game.view.rebate.openNewSerSevenDay.panels
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.item.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;
    import mortal.game.view.rebate.rank.*;
    import mortal.mvc.core.*;

    public class OpenNewSerSevBottom extends GSprite
    {
        protected var ui_1:GImageBitmap;
        protected var ui_0:GImageBitmap;
        protected var _firstName:GImageBitmap;
        protected var _rwTitle2:GImageBitmap;
        protected var _firstBg:GImageBitmap;
        protected var _firstTitle:GImageBitmap;
        protected var _firstN:GImageBitmap;
        protected var _rwTitle3:GImageBitmap;
        protected var _rwTitle4:GImageBitmap;
        protected var _roleBg:GImageBitmap;
        protected var _line1:ScaleBitmap;
        protected var _line2:ScaleBitmap;
        protected var _line3:ScaleBitmap;
        protected var _avatar:GImageBitmap;
        protected var _tip:GTextFiled;
        protected var _detailBtn:GButton;
        protected var _items1:CellsGridSprite;
        protected var _playerName:GTextFiled;
        protected var _items2:CellsGridSprite;
        protected var _items3:CellsGridSprite;
        protected var _items4:CellsGridSprite;
        protected var _rangTipTxt:GTextFiled;
        protected var _getBtn:GLoadingButton;
        protected var _tip2:GTextFiled;
        protected var _tip3:GTextFiled;
        protected var _tip4:GTextFiled;
        protected var _tip5:GTextFiled;
        private var _info:Object;

        public function OpenNewSerSevBottom()
        {
            this._info = {};
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.ui_1 = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgNumOne, 333, 0, this);
            this.ui_0 = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgNumOne, 0, 0, this);
            this._firstName = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZfirstPName, 11, 52, this);
            this._rwTitle2 = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZ2to3, 347, 16, this);
            this._firstBg = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZfirstBg, 0, 18, this);
            this._firstTitle = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZfirstTip, 109, 15, this);
            this._firstN = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevCell1_0, 68, 9, this);
            this._rwTitle3 = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZ4to10, 344, 97, this);
            this._rwTitle4 = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZ4to10, 342, 189, this);
            this._roleBg = UIFactory.gImageBitmap(ImagesConst.ChatRoleHeadBg, 39, 123, this);
            this._line1 = UIFactory.bg(2, 216, 322, 2, this, ImagesConst.SplitLine4);
            this._line2 = UIFactory.bg(336, 82, 321, 2, this, ImagesConst.SplitLine4);
            this._line3 = UIFactory.bg(335, 167, 323, 2, this, ImagesConst.SplitLine4);
            this._avatar = UIFactory.gImageBitmap("AvatarBig_2_0.png", 40, 106, this);
            this._tip = UIFactory.gTextField("" + Language.getString(71817), 2, 254, 300, 20, this, GlobalStyle.textFormatLv);
            this._detailBtn = UIFactory.gButton("" + Language.getString(71818), 261, 219, 62, 30, this, "GreenLinkButton");
            this._items1 = UIFactory.getUICompoment(CellsGridSprite);
            this._items1.colNum = 2;
            this._items1.vCellWid = 73;
            this._items1.hCellWid = 73;
            this._items1.genCellFun = this.genItem;
            this._items1.genCells(4);
            this._items1.x = 166;
            this._items1.y = 59;
            this.addChild(this._items1);
            this._playerName = UIFactory.gTextField("" + Language.getString(71819), 18, 76, 150, 25, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(15).center().setBold(true));
            this._items2 = UIFactory.getUICompoment(CellsGridSprite);
            this._items2.colNum = 3;
            this._items2.vCellWid = 73;
            this._items2.hCellWid = 73;
            this._items2.genCellFun = this.genItem;
            this._items2.genCells(3);
            this._items2.x = 423;
            this._items2.y = 6;
            this.addChild(this._items2);
            this._items3 = UIFactory.getUICompoment(CellsGridSprite);
            this._items3.colNum = 3;
            this._items3.vCellWid = 73;
            this._items3.hCellWid = 73;
            this._items3.genCellFun = this.genItem;
            this._items3.genCells(3);
            this._items3.x = 423;
            this._items3.y = 89;
            this.addChild(this._items3);
            this._items4 = UIFactory.getUICompoment(CellsGridSprite);
            this._items4.colNum = 3;
            this._items4.vCellWid = 73;
            this._items4.hCellWid = 73;
            this._items4.genCellFun = this.genItem;
            this._items4.genCells(3);
            this._items4.x = 423;
            this._items4.y = 174;
            this.addChild(this._items4);
            this._rangTipTxt = UIFactory.gTextField("", 333, 185, 95, 25, this, GlobalStyle.textFormatLv.setSize(15).center().setBold(true));
            this._getBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 342, 210, 70, 25, this);
            this._getBtn.label = "" + Language.getString(71810);
            this._tip2 = UIFactory.gTextField("" + Language.getString(71820), 338, 55, 100, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._tip3 = UIFactory.gTextField("" + Language.getString(71820), 338, 137, 100, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._tip4 = UIFactory.gTextField("" + Language.getString(71820), 124, 223, 100, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._tip5 = UIFactory.gTextField("" + Language.getString(71820), 338, 210, 100, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onGet);
            this._getBtn.enabled = false;
            this._rwTitle4.visible = false;
            this._detailBtn.configEventListener(MouseEvent.CLICK, this.onDetail);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.ui_1 = null;
            this.ui_0 = null;
            this._firstName = null;
            this._rwTitle2 = null;
            this._firstBg = null;
            this._firstTitle = null;
            this._firstN = null;
            this._rwTitle3 = null;
            this._rwTitle4 = null;
            this._roleBg = null;
            this._line1 = null;
            this._line2 = null;
            this._line3 = null;
            this._avatar = null;
            this._tip = null;
            this._detailBtn = null;
            this._items1 = null;
            this._playerName = null;
            this._items2 = null;
            this._items3 = null;
            this._items4 = null;
            this._rangTipTxt = null;
            this._getBtn = null;
            this._tip2 = null;
            this._tip3 = null;
            this._tip4 = null;
            this._tip5 = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function genItem() : RebateItem
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateItem);
            return _loc_1;
        }// end function

        public function updateBottomByDayNum(param1:int) : void
        {
            this.clear();
            this._info.dayNum = param1;
            this.updateRewards();
            this.updateGetBtn();
            return;
        }// end function

        public function updateRole(param1:SToplist, param2:int) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            this.clear();
            if (param1)
            {
                _loc_3 = param1.propertyThree;
                _loc_4 = param1.propertyTwo;
                this._avatar.visible = true;
                this._avatar.imgUrl = AvatarUtil.getPlayerAvatarUrl(_loc_3, _loc_4, AvatarUtil.Big);
                switch(param1.toplistType)
                {
                    case EToplistType._EToplistTypePlayerLevel:
                    case EToplistType._EToplistTypePlayerCombat:
                    {
                        this._playerName.text = "" + param1.entityName;
                        break;
                    }
                    default:
                    {
                        this._playerName.text = "" + param1.ownerName;
                        break;
                        break;
                    }
                }
            }
            return;
        }// end function

        private function clear() : void
        {
            if (this._avatar)
            {
                this._avatar.visible = false;
            }
            this._playerName.text = "" + Language.getString(71821);
            return;
        }// end function

        public function updateRewards() : void
        {
            var _loc_6:CellsGridSprite = null;
            var _loc_7:Array = null;
            var _loc_8:int = 0;
            var _loc_9:RebateItem = null;
            var _loc_10:SPlayerItem = null;
            var _loc_1:* = this._info.dayNum;
            var _loc_2:* = OpenServerSevenDayUtil.getRewardsByDay(_loc_1);
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = _loc_2[0];
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length)
            {
                
                _loc_6 = this["_items" + (_loc_4 + 1)] as CellsGridSprite;
                if (_loc_6)
                {
                    _loc_7 = _loc_3[_loc_4];
                    _loc_6.genCells(_loc_7.length);
                    _loc_8 = 0;
                    while (_loc_8 < _loc_7.length)
                    {
                        
                        _loc_9 = _loc_6.cellArr[_loc_8];
                        _loc_10 = _loc_7[_loc_8];
                        if (_loc_9)
                        {
                            _loc_9.updateInfo(_loc_10);
                        }
                        _loc_8++;
                    }
                }
                _loc_4++;
            }
            var _loc_5:* = _loc_2[1];
            this.updateTargetLevel(_loc_1, _loc_5);
            return;
        }// end function

        private function updateTargetLevel(param1:int, param2:Object) : void
        {
            var _loc_3:String = "";
            if (param1 == 99)
            {
                _loc_3 = "" + Language.getString(71822);
                this._rangTipTxt.text = _loc_3 + "" + Language.getString(71824);
            }
            else if (param1 == 100)
            {
                _loc_3 = "" + Language.getString(71823);
                this._rangTipTxt.text = _loc_3 + Language.getString(71824);
            }
            else
            {
                _loc_3 = "" + Cache.instance.openServerSevenDay.getNameByDay(this._info.dayNum);
                this._rangTipTxt.text = Language.getStringByParam(71825, _loc_3, param2.targetLevel);
            }
            this._firstN.imgUrl = "OpenNewSerSevCell" + param1 + "_0";
            return;
        }// end function

        public function updateGetBtn() : void
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_1:* = Cache.instance.openServerSevenDay.canGet;
            var _loc_2:* = RebateRankPanel.dayNumOut;
            var _loc_3:* = _loc_2;
            if (_loc_3 == 99 || _loc_3 == 100)
            {
                this._getBtn.visible = false;
                this._tip5.visible = true;
                return;
            }
            this._getBtn.visible = true;
            this._tip5.visible = false;
            _loc_4 = RebateUtil.getTargetType();
            _loc_5 = Cache.instance.openServerSevenDay.dayNumToCfgTargetType[_loc_3];
            if (_loc_5 == _loc_4)
            {
                _loc_6 = this.dayCanGet();
                if (_loc_6 == 1)
                {
                    this.setGetBtn(true);
                    this._getBtn.label = "" + Language.getString(71811);
                }
                else if (_loc_6 == 2)
                {
                    this.setGetBtn(false);
                    this._getBtn.label = "" + Language.getString(71812);
                }
                else
                {
                    this.setGetBtn(false);
                }
            }
            else
            {
                this.setGetBtn(false);
            }
            return;
        }// end function

        private function setGetBtn(param1:Boolean) : void
        {
            if (param1)
            {
                this._getBtn.enabled = true;
                this._getBtn.filters = null;
                EffectManager.glowFilterReg(this._getBtn);
            }
            else
            {
                EffectManager.glowFilterUnReg(this._getBtn);
                this._getBtn.enabled = false;
                this._getBtn.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        private function dayCanGet() : int
        {
            var _loc_1:* = RebateRankPanel.dayNumOut;
            var _loc_2:* = _loc_1;
            var _loc_3:* = OpenServerSevenDayUtil.getRewardsByDay(_loc_2);
            if (_loc_3 == null)
            {
                return 0;
            }
            var _loc_4:* = _loc_3[(_loc_3.length - 1)];
            var _loc_5:* = Cache.instance.openServerSevenDay.result;
            return _loc_5[_loc_4.id];
        }// end function

        private function onDetail(event:MouseEvent) : void
        {
            RebateRankPanel.instance.show();
            RebateRankPanel.instance.getByDayNum();
            return;
        }// end function

        private function onGet(event:MouseEvent) : void
        {
            var _loc_2:Object = {};
            _loc_2.dayNum = RebateRankPanel.dayNumOut;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateOpenServerSevenDayGetReward, _loc_2));
            return;
        }// end function

    }
}
